package com.untrance.shop.core.dao.bean;

import javax.persistence.Query;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.untrance.shop.common.utils.JpaUtils;
import com.untrance.shop.core.dao.UserDao;
import com.untrance.shop.model.User;

/**
 * @author eugene zadyra
 */
@Repository("userDao")
@Transactional(readOnly=true)
public class UserDaoBean extends MainDaoBean<User> implements UserDao {
	
	public UserDaoBean() {
		super(User.class);
	}

	@Override
	public User findUserByUsername(String username) {
		Query query = em.createQuery("SELECT u FROM User u" +
				" WHERE u.username=:username"
				);
		query.setParameter("username", username);
		return JpaUtils.getSingleResult(query);
	}
	
}
